<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <link rel="stylesheet" href="/css/style0.css">
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .layui-btn-primary {
            border: 0px solid #C9C9C9;
            background-color: #fff;
            color: #555;
        }
        .layui-card-body{
            text-align: center;
        }
        .layui-card-body span{
            line-height: 30px;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">统计图一</div>
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <div id="main" style="width: 100%;height:800px;"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>


    </div>
</div>
</body>
<script src="https://registry.npmmirror.com/echarts/5.5.0/files/dist/echarts.min.js"></script>
<script src="/lib/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/vue.js"></script>
<script type="text/javascript" src="/js/xadmin.js"></script>
<script>

    layui.use(['laydate','form','layer'],function() {
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#test1', //指定元素
            value: new Date(1534766888000)
        });
    })
    
    function fetchSalesDataAndUpdateChart() {
        var myChart = echarts.init(document.getElementById('main'));
        var option;

        var data = [];
        $.get("/api/source/getEchart/",function(res){
            data=res.data.priceList;
            if(res.success){
                console.log(res)
                option = {
                    xAxis: {
                        max: 'dataMax'
                    },
                    yAxis: {
                        type: 'category',
                        data:res.data.phoneList,
                        inverse: true,
                        animationDuration: 300,
                        animationDurationUpdate: 300,
                        max: 2 // only the largest 3 bars will be displayed
                    },
                    series: [
                        {
                            realtimeSort: true,
                            name: 'X',
                            type: 'bar',
                            data: data,
                            label: {
                                show: true,
                                position: 'right',
                                valueAnimation: true
                            }
                        }
                    ],
                    legend: {
                        show: true
                    },
                    animationDuration: 0,
                    animationDurationUpdate: 3000,
                    animationEasing: 'linear',
                    animationEasingUpdate: 'linear'
                };

                myChart.setOption(option)
            }else{
                xadmin.alert("初始化数据错误");
            }
        },"json")
    }

    fetchSalesDataAndUpdateChart();
    setInterval(function () {
        fetchSalesDataAndUpdateChart();
    }, 3000);

</script>

</html>
